#ifndef __BLOCK_TABLE_REGISTER_H__
#define __BLOCK_TABLE_REGISTER_H__

#include <cstring>

class BlockTableRegister{
	public:
		unsigned short int free_space;
		unsigned long int block_number;

	public:
		BlockTableRegister(){
			this->free_space = 0;
			this->block_number = 0;
		}
	
		BlockTableRegister(unsigned short free_space,unsigned long block_number){
			this->free_space = free_space;
			this->block_number = block_number;
		}
		
		BlockTableRegister(const BlockTableRegister& tr){
			this->free_space = tr.free_space;
			this->block_number = tr.block_number;
		}
		
		
		~BlockTableRegister(){
		}		
		
		BlockTableRegister& operator =(const BlockTableRegister btr){
			this->free_space = btr.free_space;
			this->block_number = btr.block_number;
			return *this;
		}
		
		static unsigned int getSize(){
			return (sizeof(unsigned long int)+sizeof(unsigned short int));
		}
				
		char* toBytes(char* data)const{
			char* temp = data;
			memcpy(temp,(char*)&free_space,sizeof(unsigned short int));
			temp += sizeof(unsigned short int);
			memcpy(temp,(char*)&block_number,sizeof(unsigned long int));
			temp += sizeof(unsigned long int);						
			
			return temp;
		}
		
		static BlockTableRegister toTableRegister(char* data){
			char* temp = data;
			unsigned long int block_number;
			unsigned short int free_space;
			
			memcpy((char*)&free_space,temp,sizeof(unsigned short int));
			temp += sizeof(unsigned short int);
			memcpy((char*)&block_number,temp,sizeof(unsigned long int));
			temp += sizeof(unsigned long int);				
			
			return BlockTableRegister(free_space,block_number);
		}
};

#endif /* __BLOCK_TABLE_REGISTER_H__ */
